package work;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBConnection {
	
	    public static final String DRIVER ="com.mysql.cj.jdbc.Driver";
	    public static final String URL="jdbc:mysql://localhost:3306/test?serverTimezone=GMT%2B8";
	   //library_management_system 是自己创建的数据库名字
	   // public static final String URL="jdbc:mysql://localhost:3306/library_management_system";mysql5.0的
	    public static final String USER="root";
	    public static final String PASSWORD="123456";

	    Connection conn =null;
	    public DBConnection(){

	        try{
	            Class.forName(DRIVER);
	        }catch (ClassNotFoundException e) {
	            e.printStackTrace();
	        }

	        try{
	            conn= DriverManager.getConnection(URL,USER,PASSWORD);
	        }catch (SQLException e) {
	            e.printStackTrace();
	        }
	    }
	    public Connection getConnection(){
	        return this.conn;
	    }


	    public void close(){
	        if(this.conn!=null){
	            try{
	                this.conn.close();
	            } catch (SQLException e) {
	                e.printStackTrace();
	            }
	        }
	    }
	    
	}
	